#include "core/lj.hpp"


namespace FastMD 
{
	
	LJ:: ~LJ() throw()
	{
	}
	
	LJ:: LJ( const Real eps, const Real sig ) throw() :
	sigma_sq(   sig * sig  ),
	_4epsilon(  4  * eps   ),
	_24epsilon( 24 * eps )
	{
		
	}
	
	
	
	Real LJ:: operator()( V3D &f, const V3D &r ) const throw()
	{
		const Real r2  = r.normsq();
		const Real q2  = sigma_sq / r2;
		const Real q6  = q2*q2*q2;
		const Real q12 = q6 * q6;
		f.mulset( _24epsilon * ( (q12+q12) - q6 ) / r2, r);
		//std::cerr << "f_LJ(" << r << ")=" << f << " (fac=" << _24epsilon * ( (q12+q12) - q6 ) / r2 << ")" << std::endl;
		return _4epsilon * ( q12 -q6 );
	}
	
	const char *LJ:: name() const throw()
	{
		return "LennardJones";
	}
	
	
}

